﻿function IndexViewModel() {
    var self = this;
    self.NavData = [];

    self.NavDataTree = [];
    self.BuildTree = function (node) {

        self.NavData.forEach(function (x, index) {

            if (x.parentId === node.id) {
                var newItem = {};
                newItem.id = x.id;
                newItem.ico = x.ico;
                newItem.route = x.route;
                newItem.itemClick = function () {
                    alert("");
                };
                newItem.title = x.title;

                newItem.children = [];

                self.BuildTree(newItem);
                if (node.id === null)
                    self.NavDataTree.push(newItem);
                else {
                    node.children.push(newItem);
                }
            }
        });
    };
    self.navItemclick = function (data, item) {
        var $target = $(item.target);
        var url = $(item.target).data("url");
        if (url == null) {
            return false;
        }
        if (url.length === 0 || url === "#") {
            return false;
        }

        $target.parents("ul").find(".active").removeClass("active");
        $target.parent().addClass("active");


        window.app.loadUI(url);

        //移动端视图点击折叠导航
        if ($(".main-footer").is(':hidden')) {
            $('.sidebar-toggle').pushMenu("toggle");

        }
        
        return false;
    };

}
